04. Access Specifiers
## Inherited Access Specifiers
Just as access specifiers (i.e. public
, protected
, and private
) define which class members users can access, the same access modifiers also define which class members users of a derived classes can access.
Public inheritance: the public and protected members of the base class listed after the specifier keep their member access in the derived class
Protected inheritance: the public and protected members of the base class listed after the specifier are protected members of the derived class
Private inheritance: the public and protected members of the base class listed after the specifier are private members of the derived class
Source: C++ reference
In the exercise below, you'll experiment with access modifiers.
Instructions
- Update the derived classes so that one has
protected
inheritance and one hasprivate
inheritance. - Try to access a
protected
member frommain()
. Is it possible? - Try to access a
private
member frommain()
. Is it possible? - Try to access a member of the base class from within the derived class that has
protected
inheritance. Is it possible? - Try to access a member of the base class from within the derived class that has
private
inheritance. Is it possible?
Workspace
This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.
Workspace Information:
- Default file path:
- Workspace type: jupyter
- Opened files (when workspace is loaded): n/a